<%-- 
    Document   : edit
    Created on : Jan 4, 2010, 11:08:19 AM
    Author     : Administrator
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<script type="application/javascript">
    function setChoosenAsCorrectOption(optionId){
        document.getElementsByName("correctOption").item(0).value = optionId;
    }
    
    function $(id){
        return document.getElementById(id);
    }
    function changeCat(id){
        $('catId').value = id;
        $('mainform').submit();
    }
</script>

<form id="mainform" method="post">
    <input type="hidden" id="catId" name="catId" value="${question.category.autoId}"/>
    <input type="hidden" name="correctOption"/>
    <table border="1">
        <tr><td colspan="3">${question.autoId!=0?"Edit Question": "Create New Question"}</td></tr>
        <tr>
            <td colspan="3">
                ${class.sgt.onlinetest.util.HtmlExtensions.getCategoryTreeHTML$[question.category]["javascript:changeCat(%d)"]}
            </td>
        </tr>
        <tr>
            <td colspan="3">Content</td>
        </tr>
        <tr>
            <td colspan="3"><textarea name="content">${question.content}</textarea></td>
        </tr>
        <c:forEach var="option" items="${question.options}" varStatus="counter">
            <tr>
                <td>${counter.count}</td>
                <td><input type="text" name="option_${option.autoId}" value="${option.content}"/></td>
                <td>
                    <c:choose>
                        <c:when test="${option.correct}">
                            <strong><em>(Correct answer)</em></strong>
                        </c:when>
                        <c:otherwise>
                            <input type="submit" "name="chooseAsCorrectOption" value="Choose as correct answer" onclick="setChoosenAsCorrectOption(${option.autoId})"/>
                            </c:otherwise>
                        </c:choose>
                </td>
            </tr>
        </c:forEach>
        <tr>
            <td>*</td>
            <td><input type="text" name="newOption"/></td>
            <td>
                <input type="submit" name="addOption" value="Add option" />
            </td>
        </tr>
        <tr>
            <td colspan="3"><input type="submit" name="save" value="Save"></td>
        </tr>
    </table>
</form>